﻿using Newtonsoft.Json.Linq;
using System;

namespace Bilibili.Model.Dynamic
{
    public sealed class Repost
    {
        public long uid { get; set; }
        public string comment { get; set; }
        public long ts { get; set; }
        public string face_url { get; set; }
        public string uname { get; set; }
        public string rp_dyn_id { get; set; }
        public string ctrl { get; set; }
        public JObject detail { get; set; }
        public string time
        {
            get
            {
                DateTime dtStart = new DateTime(1970, 1, 1);
                TimeSpan toNow = TimeSpan.FromSeconds(ts);
                DateTime dt = dtStart.Add(toNow).ToLocalTime();
                TimeSpan span = DateTime.Now - dt;
                if (span.TotalDays > 3)
                    return dt.ToString("MM-dd");
                else if (span.TotalDays > 2)
                    return string.Format("前天");
                else if (span.TotalDays > 1)
                    return string.Format("昨天");
                else if (span.TotalHours > 1)
                    return string.Format("{0}小时前", (int)Math.Floor(span.TotalHours));
                else if (span.TotalMinutes > 1)
                    return string.Format("{0}分钟前", (int)Math.Floor(span.TotalMinutes));
                else if (span.TotalSeconds >= 1)
                    return string.Format("{0}秒前", (int)Math.Floor(span.TotalSeconds));
                else
                    return "1秒前";
            }
        }
    }
}